{breadcrumbs}Manage Polls{/breadcrumbs}
<h1><img src="{image}/icons/bargraph32.png" border="0" alt="" class="titleicon"/>Manage Polls</h1>
{include file="field_errors.tpl"}
<p><a href="{$GLOBALS.site_url}/manage-polls/?action=new" class="grayButton">Add a New Poll</a></p>
{capture assign="trAskToDelete"}[[Are you sure you want to delete the selected Poll(s)?]]{/capture}
{capture assign="notificationToEmptyChoice"}[[Please choose a poll first]]{/capture}
{capture assign="information"}[[Information]]{/capture}

<form action="">
	<input type="hidden" name="action" value="save_display_setting" />
	<table>
		<tr id="clearTable">
            <td>Polls Block Display On Front-end  &nbsp;</td>
            <td align=center>
                <select name="settings[show_polls_on_main_page]" onchange="javascript: form.submit();">
                    <option value="0"{if $show_polls_on_main_page == 0} selected="selected"{/if}>disable</option>
                    <option value="1"{if $show_polls_on_main_page == 1} selected="selected"{/if}>enable</option>
                </select>
            </td>
            <td></td>
		</tr>
	</table>
</form>


<form method="post" action="" name="resultsForm">
    <div class="box" id="displayResults">
        <div class="box-header">
            <div class="actionWithSelected">
                [[Actions with Selected]]:
                <input type="submit" value="[[Activate]]" class="grayButton" onclick="return submitForm('activate');" />
                <input type="submit" value="[[Deactivate]]" class="grayButton" onclick="return submitForm('deactivate');" />
                &nbsp;<input type="submit" value="[[Delete]]" class="deletebutton" onclick="return submitForm('delete');" />
            </div>

                <div class="pagination">
                    {if $page-1 > 0}&nbsp;<a href="?page={$page-1}&amp;sorting_field={$sorting_field}&amp;sorting_order={$sorting_order}&amp;items_per_page={$items_per_page}">[[Previous]]</a>{else}[[Previous]]{/if}
                    {if $page-3 > 0}&nbsp;<a href="?page=1&amp;sorting_field={$sorting_field}&amp;sorting_order={$sorting_order}&amp;items_per_page={$items_per_page}">1</a>{/if}
                    {if $page-3 > 1}&nbsp;...{/if}
                    {if $page-2 > 0}&nbsp;<a href="?page={$page-2}&amp;sorting_field={$sorting_field}&amp;sorting_order={$sorting_order}&amp;items_per_page={$items_per_page}">{$page-2}</a>{/if}
                    {if $page-1 > 0}&nbsp;<a href="?page={$page-1}&amp;sorting_field={$sorting_field}&amp;sorting_order={$sorting_order}&amp;items_per_page={$items_per_page}">{$page-1}</a>{/if}
                        <strong>{$page}</strong>
                    {if $page+1 <= $totalPages}&nbsp;<a href="?page={$page+1}&amp;sorting_field={$sorting_field}&amp;sorting_order={$sorting_order}&amp;items_per_page={$items_per_page}">{$page+1}</a>{/if}
                    {if $page+2 <= $totalPages}&nbsp;<a href="?page={$page+2}&amp;sorting_field={$sorting_field}&amp;sorting_order={$sorting_order}&amp;items_per_page={$items_per_page}">{$page+2}</a>{/if}
                    {if $page+3 < $totalPages}&nbsp;...{/if}
                    {if $page+3 < $totalPages + 1}&nbsp;<a href="?page={$totalPages}&amp;sorting_field={$sorting_field}&amp;sorting_order={$sorting_order}&amp;items_per_page={$items_per_page}">{$totalPages}</a>{/if}
                    {if $page+1 <= $totalPages}&nbsp;<a href="?page={$page+1}&amp;sorting_field={$sorting_field}&amp;sorting_order={$sorting_order}&amp;items_per_page={$items_per_page}">[[Next]]</a>{else}[[Next]]{/if}
                </div>

                <div class="numberPerPage">
                    per page:
                    <select name="items_per_page" onchange="window.location = '?restore=1&items_per_page='+this.value;" class="perPage">
                        <option value="10" {if $items_per_page == 10}selected="selected"{/if}>10</option>
                        <option value="20" {if $items_per_page == 20}selected="selected"{/if}>20</option>
                        <option value="50" {if $items_per_page == 50}selected="selected"{/if}>50</option>
                        <option value="100" {if $items_per_page == 100}selected="selected"{/if}>100</option>
                    </select>
                </div>

                <input type="hidden" name="page" value="1" />
                <input type="hidden" name="sorting_field" value="{$sorting_field}" />
                <input type="hidden" name="sorting_order" value="{$sorting_order}" />
        </div>
        <div class="innerpadding">
            <div id="displayResultsTable">
                <input type="hidden" name="action"  id="actionName" value="" />
                <table class="basetable" width="100%">
                    <thead>
                    <tr>
                        <th><input type="checkbox" id="all_checkboxes_control"></th>
                        <th>
                            <a href="?sorting_field=sid&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'sid'}DESC{else}ASC{/if}">[[ID]]</a>
                        {if $sorting_field == 'sid'}
                            {if $sorting_order == 'ASC'}
                                <img src="{image}b_up_arrow.gif" alt="Up" />
                                {else}
                                <img src="{image}b_down_arrow.gif" alt="Down" />
                            {/if}
                        {/if}
                        </th>
                        <th>
                            <a href="?sorting_field=question&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'question'}DESC{else}ASC{/if}">[[Poll Question]]</a>
                        {if $sorting_field == 'question'}
                            {if $sorting_order == 'ASC'}
                                <img src="{image}b_up_arrow.gif" alt="Up" />
                                {else}
                                <img src="{image}b_down_arrow.gif" alt="Down" />
                            {/if}
                        {/if}
                        </th>
                        <th>
                            <a href="?sorting_field=user_group&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'user_group'}DESC{else}ASC{/if}">[[User Group]]</a>
                        {if $sorting_field == 'user_group'}
                            {if $sorting_order == 'ASC'}
                                <img src="{image}b_up_arrow.gif" alt="Up" />
                                {else}
                                <img src="{image}b_down_arrow.gif" alt="Down" />
                            {/if}
                        {/if}
                        </th>
                        <th>
                            <a href="?sorting_field=start_date&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'start_date'}DESC{else}ASC{/if}">[[Start Date]]</a>
                        {if $sorting_field == 'start_date'}
                            {if $sorting_order == 'ASC'}
                                <img src="{image}b_up_arrow.gif" alt="Up" />
                                {else}
                                <img src="{image}b_down_arrow.gif" alt="Down" />
                            {/if}
                        {/if}
                        </th>
                        <th>
                            <a href="?sorting_field=end_date&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'end_date'}DESC{else}ASC{/if}">[[Expiration Date]]</a>
                        {if $sorting_field == 'end_date'}
                            {if $sorting_order == 'ASC'}
                                <img src="{image}b_up_arrow.gif" alt="Up" />
                                {else}
                                <img src="{image}b_down_arrow.gif" alt="Down" />
                            {/if}
                        {/if}
                        </th>
                        <th>
                            <a href="?sorting_field=status&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'status'}DESC{else}ASC{/if}">[[Status]]</a>
                        {if $sorting_field == 'status'}
                            {if $sorting_order == 'ASC'}
                                <img src="{image}b_up_arrow.gif" alt="Up" />
                                {else}
                                <img src="{image}b_down_arrow.gif" alt="Down" />
                            {/if}
                        {/if}
                        </th>
                        <th>
                            <a href="?sorting_field=language&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'language'}DESC{else}ASC{/if}">[[Language]]</a>
                        {if $sorting_field == 'language'}
                            {if $sorting_order == 'ASC'}
                                <img src="{image}b_up_arrow.gif" alt="Up" />
                                {else}
                                <img src="{image}b_down_arrow.gif" alt="Down" />
                            {/if}
                        {/if}
                        </th>
                        <th colspan="2">[[Actions]]</th>
                    </tr>
                    </thead>
                    <tbody>
                    {foreach from=$pollsInfo item=poll name=fields_block}
                    <tr class="{cycle values = 'evenrow,oddrow' advance=false}" onmouseover="this.className='highlightrow'" onmouseout="this.className='{cycle values = 'evenrow,oddrow'}'">
                        <td><input type="checkbox" name="polls[{$poll.sid}]" value="1" id="checkbox_{$smarty.foreach.fields_block.iteration}" /></td>
                        <td>{$poll.sid}</td>
                        <td>{$poll.question}</td>
                        <td>{$poll.user_group}</td>
                        <td>{$poll.start_date}</td>
                        <td>{$poll.end_date}</td>
                        <td>
                            {if $poll.active == 1}[[Active]]{else}[[Not Active]]{/if}
                        </td>
                        <td>
                            {foreach from=$frontendLanguages item=language}
								{if $language.id == $poll.language}{$language.caption}{/if}
							{/foreach}
                        </td>
                        <td><a href="{$GLOBALS.site_url}/manage-polls/?action=edit&amp;sid={$poll.sid}" title="Edit" class="editbutton">[[Edit]]</a></td>
                        <td><a href="{$GLOBALS.site_url}/manage-polls/?action=delete&amp;sid={$poll.sid}" onclick="return confirm('{$trAskToDelete|escape:"javascript"|escape:"html"}')" title="Delete" class="deletebutton">[[Delete]]</a></td>
                    </tr>
                    {/foreach}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</form>

<script>
var total={$smarty.foreach.fields_block.total};
{literal}

function popUpMessageWindow(widthWin, heightWin, title, message){
	$("#messageBox").dialog( 'destroy' ).html(message);
	$("#messageBox").dialog({
		width: widthWin,
		height: heightWin,
		title: title
	}).dialog( 'open' );

	return false;
}

function set_checkbox(param) {
	for (var i = 1; i <= total; i++) {
		var checkbox = document.getElementById('checkbox_' + i);
		if (checkbox) {
			checkbox.checked = param;
		}
	}
}

$("#all_checkboxes_control").click(function() {
	if ( this.checked == false) {
		set_checkbox(false);
	} else {
		set_checkbox(true);
	}
} );

function submitForm(action) {
	if ($("input:checked").length == 0) {
		popUpMessageWindow(300, 100, "{/literal}{$information|escape:'javascript'}", "{$notificationToEmptyChoice|escape:"javascript"}{literal}");
	} else {
		if (action == "delete") {
			if (!confirm('{/literal}{$trAskToDelete|escape:"javascript"}{literal}')) {
				return false;
			}
		}
		document.getElementById("actionName").value = action;
		var form = document.resultsForm;
		form.submit();
	}
	return false;
}
{/literal}
</script>
